<template>
  <!-- 预警决策主页 -->
  <div>
    <div class="body">
      <div class="container">
        <div class="warning-side borderStyle centerbox relative">
          <div class="title centertitleStyle centerbox title-relative">主变负载</div>
          <WarningDuty :mainLoadCount="mainLoadCount" :mainLoadList="mainLoadList" />
        </div>
        <div class="warning-center borderStyle centerbox relative">
          <div class="title centertitleStyle centerbox title-relative" @click="goPage('zxjc')">在线监测</div>
          <WarningOnlie
            :CurrentOrg="CurrentOrg"
            :dzLoginName="dzLoginName"
            :deviceTotal="deviceTotal"
            :abnormalData="abnormalData"
          />
        </div>
        <div class="warning-side borderStyle centerbox relative">
          <div class="title centertitleStyle centerbox title-relative" @click="goPage('ddjc')">带电检测</div>
          <WarningCharg
            :CurrentOrg="CurrentOrg"
            :dzLoginName="dzLoginName"
            :electricTotal="electricTotal"
            :electricData="electricData"
          />
        </div>
      </div>
      <div class="container">
        <div class="warning-side borderStyle centerbox relative">
          <!-- <div class="title centertitleStyle centerbox title-relative" @click="goSecond('countermeasures')" >十八项反措</div> -->
          <div class="title centertitleStyle centerbox title-relative">十八项反措</div>
          <WarningEighteen />
        </div>
        <div class="warning-center borderStyle centerbox relative">
          <!-- <div class="title centertitleStyleOne title-relative" @click="goSecond('defects')">缺陷</div>
          <div class="title centertitleStyleTwo title-relative" @click="goSecond('danger')">隐患</div>-->
          <div class="title centertitleStyleOne title-relative">缺陷</div>
          <div class="title centertitleStyleTwo title-relative">隐患</div>
          <WarningDefects />
        </div>
        <div class="warning-side borderStyle centerbox relative">
          <!-- <div class="title centertitleStyle centerbox title-relative" @click="goSmart()">智能联动</div> -->
          <div class="title centertitleStyle centerbox title-relative">智能联动</div>
          <WarningSmart :linkageList="linkageList" />
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { EChartOption } from "echarts";
import axios from "axios";
import WarningDuty from "../../commponents/WarningDuty/index.vue";
import WarningOnlie from "../../commponents/WarningOnlie/index.vue";
import WarningCharg from "../../commponents/WarningCharg/index.vue";
import WarningEighteen from "../../commponents/WarningEighteen/index.vue";
import WarningDefects from "../../commponents/WarningDefects/index.vue";
import WarningSmart from "../../commponents/WarningSmart/index.vue";
import { JointInspectionModule } from "@/store/modules/JointInspection";

@Component({
  components: {
    WarningDuty,
    WarningOnlie,
    WarningCharg,
    WarningEighteen,
    WarningDefects,
    WarningSmart,
  },
})
export default class WarningToSolve extends Vue {
  // 所属地市
  private localCity: string = "8a1ea5c64bdebad1014bdebc55c80003";
  // 主变负载负载率统计
  private mainLoadCount = [];
  // 主变负载率滚动列表
  private mainLoadList = [];
  // 智能联动滚动列表
  private linkageList = [];
  // 当前地市信息
  private CurrentOrg: any = {};
  // 地市名
  private dzLoginName: string = "";
  // 在线监测装备总数
  private deviceTotal = 0;
  // 在线监测异常装备数据
  private abnormalData = [
    {
      total: 0,
      zb: 0,
      zhdq: 0,
      kgg: 0,
      blq: 0,
    },
  ];
  // 带电检测装备总数
  private electricTotal = {
    yctotal: 0,
    yictotal: 0,
  };
  // 带电检测异常装备数据
  private electricData = [
    {
      yicsb: 0, //已测设备总数
      ycsb: 0, //异常设备总数
    },
    {
      // 正常
      kggcsb: 0,
      kggztd: 0,
      hwcw: 0,
      gistgp: 0,
      giscsb: 0,
    },
    {
      // 异常
      kggcsbyc: 0,
      kggztdyc: 0,
      hwcwyc: 0,
      gistgpyc: 0,
      giscsbyc: 0,
    },
    {
      // 总数
      kggcsbcd: 0,
      kggztdcd: 0,
      hwcwcd: 0,
      gistgpcd: 0,
      giscsbcd: 0,
    },
  ];

  // 所属地市
  get CompanyList() {
    let CompanyList = JointInspectionModule.CompanyList || [];
    return CompanyList;
  }

  // 初始化页面
  private init() {
    var localCity = "";
    if (this.CompanyList && this.CompanyList[0] && this.CompanyList[0].code) {
      localCity = this.CompanyList[0].code;
    } else {
      localCity = "8a1ea5c64bdebad1014bdebc6047087b";
    }
    // 请求主变负载负载率统计接口、二级页面统计接口
    (this as any).$services
      .mainLoadCount({
        method: "get",
        data: { localCity: localCity },
      })
      .then((result: any) => {
        console.log("主变负载主页值:", result.data);
        this.mainLoadCount = result.data;
      })
      .catch((err: object) => {
        console.log(err);
      });
    // 请求主变负载率滚动列表
    (this as any).$services
      .mainLoadList({
        method: "get",
        data: { localCity: localCity },
      })
      .then((result: any) => {
        // console.log("主变负载率滚动列表:", result.data.slice(0, 15));
        this.mainLoadList = result.data.slice(0, 15);
      })
      .catch((err: object) => {
        console.log(err);
      });
    // 请求智能联动滚动列表
    (this as any).$services
      .linkageList({
        method: "get",
        data: { localCity: localCity },
      })
      .then((result: any) => {
        // console.log("智能联动滚动列表:", result.data.slice(0, 15));
        if (result.data && result.data.length) {
          this.linkageList = result.data.slice(0, 15);
          // console.log(this.linkageList);
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // 获取当前地市
    (this as any).$services
      .getCurrentOrg({
        method: "get",
        data: {},
      })
      .then((result: any) => {
        // console.log("当前地市:", result);
        this.CurrentOrg = result.data;
        this.getdzLoginName(this.CurrentOrg.SSDSBM);
        this.getZzsl(this.CurrentOrg.SSDSMC);
        this.getSbslYc(this.CurrentOrg.SSDSMC);
        this.getDdjcSbzs2(this.CurrentOrg.SSDSMC);
        this.getDdjcYcsl(this.CurrentOrg.SSDSMC);
      })
      .catch((err: object) => {
        console.log(err);
      });
  }

  // 获取在线监测装置总数
  private getZzsl(ssdsmc: string) {
    axios({
      url: (window as any).VUE_APP_ONLINE + "/epribigdata/xinyi_ztZxjc/getZzsl",
      method: "get",
      params: { ssdsmc: ssdsmc },
    })
      .then((result: any) => {
        console.log("在线监测装置总数:", result);
        let data = result;
        let zzzs1 = 0;
        let yczzs1 = 0;
        let zzzs2 = 0;
        let yczzs2 = 0;
        let zzzs3 = 0;
        let yczzs3 = 0;
        let zzzs4 = 0;
        let yczzs4 = 0;
        let zzzs5 = 0;
        let yczzs5 = 0;
        let zzzs6 = 0;
        let yczzs6 = 0;
        let zzzs7 = 0;
        let yczzs7 = 0;
        data.map((v, i) => {
          if (v.JCLX == "变压器油中溶解气体监测") {
            zzzs1 = v.ZZSL;
            yczzs1 = v.ZZYCSL;
          } else if (v.JCLX == "变压器铁芯接地电流监测") {
            zzzs2 = v.ZZSL;
            yczzs2 = v.ZZYCSL;
          } else if (v.JCLX == "变压器套管绝缘监测") {
            zzzs3 = v.ZZSL;
            yczzs3 = v.ZZYCSL;
          } else if (v.JCLX == "变压器局部放电监测") {
            zzzs4 = v.ZZSL;
            yczzs4 = v.ZZYCSL;
          } else if (v.JCLX == "GIS/断路器SF6气体压力监测") {
            zzzs5 = v.ZZSL;
            yczzs5 = v.ZZYCSL;
          } else if (v.JCLX == "GIS/断路器局部放电监测") {
            zzzs6 = v.ZZSL;
            yczzs6 = v.ZZYCSL;
          } else if (v.JCLX == "避雷器全电流监测") {
            zzzs7 = v.ZZSL;
            yczzs7 = v.ZZYCSL;
          }
        });
        this.deviceTotal =
          zzzs1 + zzzs2 + zzzs3 + zzzs4 + zzzs5 + zzzs6 + zzzs7; //装置总数
      })
      .catch((err: object) => {
        console.log(err);
      });
  }

  // 获取在线监测设备异常数据汇总
  private getSbslYc(ssdsmc: string) {
    axios({
      url:
        (window as any).VUE_APP_ONLINE + "/epribigdata/xinyi_ztZxjc/getSbslYc",
      method: "get",
      params: { ssdsmc: ssdsmc },
    })
      .then((result: any) => {
        console.log("在线监测设备异常数据汇总:", result);
        let data = result;
        let zb = 0;
        let zhdq = 0;
        let kgg = 0;
        let blq = 0;
        data.map((v, i) => {
          if (v.SBLX == "0301") {
            //主变压器
            zb = v.YUJS;
          }
          if (v.SBLX == "0321") {
            //组合电器
            zhdq = v.YUJS;
          }
          if (v.SBLX == "0322") {
            //开关柜
            kgg = v.YUJS;
          }
          if (v.SBLX == "0318") {
            //避雷器
            blq = v.YUJS;
          }
        });
        this.abnormalData = [
          {
            total: zb + zhdq + kgg + blq,
            zb: zb,
            zhdq: zhdq,
            kgg: kgg,
            blq: blq,
          },
        ]; //设备异常数据
        // console.log("this.abnormalData:", this.abnormalData);
      })
      .catch((err: object) => {
        console.log(err);
      });
  }

  // 获取带电检测装置总数
  private getDdjcSbzs2(ssdsmc: string) {
    axios({
      url:
        (window as any).VUE_APP_ONLINE +
        "/epribigdata/xinyi_ztZxjc/getDdjcSbzs2",
      method: "get",
      params: { ssdsmc: ssdsmc },
    })
      .then((result: any) => {
        // console.log("应测/已测设备总数:", result);
        let data = result;
        console.log(data);
        let yctotal =
          data[0].KGGCSBYC +
          data[0].GISCSBYC +
          data[0].HWYC +
          data[0].GISTGPYC +
          data[0].KGGZTDYC; // 应测设备总数
        let yictotal =
          data[0].KGGCSBYIC +
          data[0].GISCSBYIC +
          data[0].HWYIC +
          data[0].GISTGPYIC +
          data[0].KGGZTDYIC; // 已测设备总数
        this.electricTotal = {
          yctotal: yctotal,
          yictotal: yictotal,
        };
      })
      .catch((err: object) => {
        console.log(err);
      });
  }

  // 获取带电检测设备异常数据汇总
  private getDdjcYcsl(ssdsmc: string) {
    let date = new Date();
    let month =
      Number(date.getMonth() + 1) < 10
        ? "0" + Number(date.getMonth() + 1)
        : Number(date.getMonth() + 1);
    let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    let time = date.getFullYear() + "-" + month + "-" + day;
    // console.log("time:",time);
    axios({
      url:
        (window as any).VUE_APP_ONLINE +
        "/epribigdata/xinyi_ztZxjc/getDdjcYcsl",
      method: "get",
      params: { ssdsmc: ssdsmc, startDate: "2019-01-01", endDate: time },
    })
      .then((result: any) => {
        // console.log("带电检测设备异常数据汇总:", result);
        let data = result;
        let sbzsCount = 0;
        let ljyjslCount = 0;
        //    正常          异常          总数
        let kggcsb = 0;
        let kggcsbyc = 0;
        let kggcsbcd = 0; //开关柜超声波
        let kggztd = 0;
        let kggztdyc = 0;
        let kggztdcd = 0; //开关柜暂态地
        let hwcw = 0;
        let hwcwyc = 0;
        let hwcwcd = 0; //红外测温
        let gistgp = 0;
        let gistgpyc = 0;
        let gistgpcd = 0; //GIS特高频
        let giscsb = 0;
        let giscsbyc = 0;
        let giscsbcd = 0; //GIS超声波
        data.map((v, i) => {
          let sbzs = v.SBZS;
          let ljyjsl = v.LJYJSL;
          sbzsCount = Number(sbzs) + sbzsCount; //已测设备
          ljyjslCount = Number(ljyjsl) + ljyjslCount; //异常设备
          if ("开关柜暂态地电压检测" == v.JCLX) {
            kggztd = sbzs - ljyjsl; //开关柜暂态地
            kggztdyc = ljyjsl; //开关柜暂态地异常
            kggztdcd = sbzs; //开关柜暂态地总测点
          }
          if ("GIS特高频（UHF）局部放电检测" == v.JCLX) {
            gistgp = sbzs - ljyjsl; //GIS特高频
            gistgpyc = ljyjsl; //GIS特高频异常
            gistgpcd = sbzs; //GIS特高频总测点
          }
          if ("开关柜超声波局部放电检测" == v.JCLX) {
            kggcsb = sbzs - ljyjsl; //开关柜超声波已完成
            kggcsbyc = ljyjsl; //开关柜超声波异常
            kggcsbcd = sbzs; //开关柜超声波总测点
          }
          if ("GIS超声（AE）局部放电检测" == v.JCLX) {
            giscsb = sbzs - ljyjsl; //GIS超声波
            giscsbyc = ljyjsl; //GIS超声波异常
            giscsbcd = sbzs; //GIS超声波总测点
          }
          if ("红外测温检测" == v.JCLX) {
            hwcw = sbzs - ljyjsl; //红外测温
            hwcwyc = ljyjsl; //红外测温异常
            hwcwcd = sbzs; //红外测温总测点
          }
        });
        // 带电检测设备异常数据
        this.electricData = [
          {
            yicsb: sbzsCount, //已测设备总数
            ycsb: ljyjslCount, //异常设备总数
          },
          {
            // 正常
            kggcsb: kggcsb,
            kggztd: kggztd,
            hwcw: hwcw,
            gistgp: gistgp,
            giscsb: giscsb,
          },
          {
            // 异常
            kggcsbyc: kggcsbyc,
            kggztdyc: kggztdyc,
            hwcwyc: hwcwyc,
            gistgpyc: gistgpyc,
            giscsbyc: giscsbyc,
          },
          {
            // 总数
            kggcsbcd: kggcsbcd,
            kggztdcd: kggztdcd,
            hwcwcd: hwcwcd,
            gistgpcd: gistgpcd,
            giscsbcd: giscsbcd,
          },
        ];
        // console.log("this.electricData:", this.electricData);
      })
      .catch((err: object) => {
        console.log(err);
      });
  }

  // 获取dzLoginName
  private getdzLoginName(ssdsBm) {
    switch (ssdsBm) {
      case "8a1ea5c64bdebad1014bdebc55c80318":
        this.dzLoginName = "8210180073A";
        break; //威海
      case "8a1ea5c64bdebad1014bdebc5c2104ea":
        this.dzLoginName = "890720535XA";
        break; //莱芜
      case "8a1ea5c64bdebad1014bdebc6047087b":
        this.dzLoginName = "8908257519A";
        break; //省检修
      case "8a1ea5c64bdebad1014bdebc5c21078c":
        this.dzLoginName = "7206100035A";
        break; //泰安
      case "8a1ea5c64bdebad1014bdebc55c80003":
        this.dzLoginName = "7302120039A";
        break; //济南
      case "8a1ea5c64bdebad1014bdebc55c80270":
        this.dzLoginName = "8702014019A";
        break; // 淄博
      case "8a1ea5c64bdebad1014bdebc55c80079":
        this.dzLoginName = "6606036718A";
        break; //青岛
      case "8a1ea5c64bdebad1014bdebc55c803a2":
        this.dzLoginName = "8009210031A";
        break; //烟台
      case "8a1ea5c64bdebad1014bdebc5c210469":
        this.dzLoginName = "8212030011A";
        break; //济宁
      case "8a1ea5c64bdebad1014bdebc6047083c":
        this.dzLoginName = "8110182437A";
        break; //滨州
      case "8a1ea5c64bdebad1014bdebc5c210656":
        this.dzLoginName = "8511094831A";
        break; //临沂
      case "8a1ea5c64bdebad1014bdebc5c21040c":
        this.dzLoginName = "9411111218A";
        break; //菏泽
      case "8a1ea5c64bdebad1014bdebc604707ec":
        this.dzLoginName = "7110134047A";
        break; //德州
      case "8a1ea5c64bdebad1014bdebc5c21073c":
        this.dzLoginName = "7110110813A";
        break; //东营
      case "8a1ea5c64bdebad1014bdebc5c2105ef":
        this.dzLoginName = "6710293010A";
        break; //聊城
      case "8a1ea5c64bdebad1014bdebc5c2106cc":
        this.dzLoginName = "7511262974A";
        break; //日照
      case "8a1ea5c64bdebad1014bdebc55c80162":
        this.dzLoginName = "6911192217A";
        break; //潍坊
      case "8a1ea5c64bdebad1014bdebc5c21053d":
        this.dzLoginName = "840115183XA";
        break; //枣庄
      case "":
        ssdsBm = "8a1ea5c64bdebad1014bdebc4cbf0001";
        this.dzLoginName = "wangnaide";
        break; //省公司
    }
  }

  created() {
    this.init();
  }

  // 跳转到二级页面
  private goSecond(url: string) {
    this.$router.push({
      path: "/warningtosolve/" + url,
    });
  }

  // 跳转到联动管理页面
  private goSmart() {
    this.$router.push({
      path: "/auxiliarymonitor/linkage",
    });
  }

  // 在线监测/带电检测标题跳转页面
  private goPage(tail: string) {
    window.open(
      "http://10.193.23.21:28883/epribigdata/jsp/index.html?ssdsid=" +
        this.CurrentOrg.SSDSBM +
        "&&loginname=" +
        this.dzLoginName +
        "A&bq=" +
        tail
    );
    // if (tail == "ddjc") {
    //   // iframe嵌套 已测设备链接跳转页面
    //   let list = "";
    //   if (this.CurrentOrg.SSDSBM == "8a1ea5c64bdebad1014bdebc4cbf0001") {
    //     //省公司
    //     list = "jczt=0&ssds=";
    //   } else {
    //     //地市公司
    //     list = "jczt=0&ssds=" + this.CurrentOrg.SSDSBM;
    //   }
    //   this.$router.push({
    //     path: "xyddjc",
    //     query: {
    //       list: list,
    //       urlType: "ddjc",
    //     },
    //   });
    // } else {
    //   // iframe嵌套 装置总数跳转页面
    //   let list = "";
    //   if (this.CurrentOrg.SSDSBM == "8a1ea5c64bdebad1014bdebc4cbf0001") {
    //     //省公司
    //     list = "ssds=" + null + "&zzzt=null&yxzt=1";
    //   } else {
    //     //地市公司
    //     list = "ssds=" + this.CurrentOrg.SSDSMC + "&zzzt=null&yxzt=1";
    //   }
    //   this.$router.push({
    //     path: "xyddjc",
    //     query: {
    //       list: list,
    //       urlType: "yczz",
    //     },
    //   });
    // }
  }
}
</script>

<style lang='scss' scoped>
.body {
  widows: 100%;
  height: 100%;
  // background-color: gray;
  padding: 0.2rem 0.24rem 0.24rem 0.24rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  .container {
    height: 48.7%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    // background-color: pink;
    .warning-side {
      width: 5.7rem;
      height: 100%;
      // background-color: rgb(148, 148, 148);
      .title {
        cursor: pointer;
        z-index: 1;
      }
    }
    .warning-center {
      width: 6.86rem;
      height: 100%;
      // background-color: gray;
      .title {
        cursor: pointer;
        z-index: 1;
      }
    }
  }
}
</style>